package com.ruoyi.applet.order.service.impl;

import com.ruoyi.applet.entity.OrdOrderApplet;
import com.ruoyi.applet.entity.PageR;
import com.ruoyi.applet.order.domain.OrdOrder;
import com.ruoyi.applet.order.mapper.OrdOrderMapper;
import com.ruoyi.applet.order.service.IOrdOrderService;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单Service业务层处理
 * @author ruoyi
 * @date 2025-01-02
 */
@Service
public class OrdOrderServiceImpl implements IOrdOrderService {
    
    @Resource
    private OrdOrderMapper ordOrderMapper;
    
    /**
     * 查询订单
     * @param id 订单主键
     * @return 订单
     */
    @Override
    public OrdOrder selectOrdOrderById(Long id) {
        return ordOrderMapper.selectOrdOrderById(id);
    }
    
    /**
     * 查询订单列表
     * @param ordOrder 订单
     * @return 订单
     */
    @Override
    public List<OrdOrder> selectOrdOrderList(OrdOrder ordOrder) {
        return ordOrderMapper.selectOrdOrderList(ordOrder);
    }
    
    /**
     * 新增订单
     * @param ordOrder 订单
     * @return 结果
     */
    @Override
    public int insertOrdOrder(OrdOrder ordOrder) {
        ordOrder.setCreateTime(DateUtils.getNowDate());
        return ordOrderMapper.insertOrdOrder(ordOrder);
    }
    
    /**
     * 修改订单
     * @param ordOrder 订单
     * @return 结果
     */
    @Override
    public int updateOrdOrder(OrdOrder ordOrder) {
        ordOrder.setUpdateTime(DateUtils.getNowDate());
        return ordOrderMapper.updateOrdOrder(ordOrder);
    }
    
    /**
     * 批量删除订单
     * @param ids 需要删除的订单主键
     * @return 结果
     */
    @Override
    public int deleteOrdOrderByIds(String ids) {
        return ordOrderMapper.deleteOrdOrderByIds(Convert.toStrArray(ids));
    }
    
    /**
     * 删除订单信息
     * @param id 订单主键
     * @return 结果
     */
    @Override
    public int deleteOrdOrderById(Long id) {
        return ordOrderMapper.deleteOrdOrderById(id);
    }
    
    @Override
    public PageR<OrdOrder> selectAppletOrdOrderList(OrdOrderApplet ordOrderApplet) {
        int count = ordOrderMapper.selectAppletOrdOrderCount(ordOrderApplet);
        PageR<OrdOrder> pageR = new PageR<>();
        pageR.setPageNo(ordOrderApplet.getPageNo());
        pageR.setPageSize(ordOrderApplet.getPageSize());
        pageR.setTotal(count);
        if (count == 0) {
            return pageR;
        }
        int start = (ordOrderApplet.getPageNo() - 1) * ordOrderApplet.getPageSize();
        List<OrdOrder> shoppingCartAppletList = ordOrderMapper.selectAppletOrdOrderList(ordOrderApplet, ordOrderApplet.getPageSize(), start);
        
        pageR.setReCords(shoppingCartAppletList);
        return pageR;
    }
}
